package com.aaa.PController;

import com.aaa.Entity.User;
import com.aaa.Service.UserService;
import com.aaa.util.DefaultMsg;
import com.aaa.util.TableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    /*
    * 跳转到用户列表界面
    * */
    @RequestMapping("/toList")
    public String toList(){
        return "user/list";
    }
    @RequestMapping("/listData")
    @ResponseBody
    public TableData<User> listData(@RequestParam(defaultValue = "")String keyword,Integer page,Integer limit){
        TableData<User> tableData=userService.page(keyword,page,limit);
        return tableData;
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public DefaultMsg saveOrUpdate(User user){
        DefaultMsg defaultMsg = userService.saveOrUpdate(user);
        return defaultMsg;
    }
    @RequestMapping("/delete")
    @ResponseBody
    public DefaultMsg delete(Long id){
        DefaultMsg defaultMsg = userService.delete(id);
        return defaultMsg;
    }
}
